package com.yunzainfo.demo.mq.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yunzainfo.demo.mq.entity.BaseUsers;
import com.yunzainfo.demo.mq.entity.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author admin
 * @date 2018/10/10
 */

@RestController
@RequestMapping("/msg")
public class MsgController {
    @Autowired
    JmsTemplate jmsTemplate;

    @RequestMapping("/send")
    public ResponseEntity send(String destination, BaseUsers baseUsers) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        String msg = objectMapper.writeValueAsString(baseUsers);
        jmsTemplate.send(destination, new Msg(msg));
        return ResponseEntity.ok("ok");
    }
}
